package com.cheng.example.atguigu.view3.chapter02;

/*
 * @author 程帅
 * @createTime: 2020/11/15 21:10
 * @Created: with IntelliJ IDEA.
 */
public class Test {

    public static void main(String[] args) {
        String str1 = new StringBuffer("58").append("tongcheng").toString();
        System.out.println(str1);
        System.out.println(str1.intern());
        System.out.println(str1==str1.intern());

//        String str2 = new StringBuffer("58").append("tongcheng").toString();
//        System.out.println(str2);
//        System.out.println(str2.intern());
//        System.out.println(str2==str2.intern()); // false

//        58tongcheng
//        58tongcheng
//        true
//        58tongcheng
//        58tongcheng
//        false

        System.out.println();
        String str2 = new StringBuffer("ja").append("va").toString();
        System.out.println(str2);
        System.out.println(str2.intern());
        System.out.println(str2==str2.intern());
    }
}
